package com.fruitshop.info.manager.dao;

import com.fruitshop.info.manager.domain.Manager;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

@SuppressWarnings("all")
public class ManagerDao {
    ArrayList<Manager> manList = new ArrayList<>();

    public ArrayList<Manager> login() {
        //调用read方法将信息添加到集合中
        read();
        //将集合返回给调用者
        return manList;
    }
    //读取保存在本地文件的管理员信息
    public void read() {
        try {
            BufferedReader reader = new BufferedReader(new FileReader("myfruit-shop-info-manager\\user.txt"));
            String line;
            while((line = reader.readLine())!=null) {
                String[] str = line.split(",");
                Manager man = new Manager(str[0], str[1]);
                //将读取道德信息切割后封装到管理员对象中,再添加到集合中
                manList.add(man);
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
